package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingLevel;
import com.zzyl.nursing.service.INursingLevelService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理等级Controller
 *
 * @author zxw
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/nursing/level")
public class NursingLevelController extends BaseController {
        @Autowired
        private INursingLevelService nursingLevelService;

        /**
         * 分页查询护理等级
         */
        @PreAuthorize("@ss.hasPermi('nursing:level:list')")
        @GetMapping("/list")
        public TableDataInfo list(NursingLevel nursingLevel) {
            startPage();
            List<NursingLevel> list = nursingLevelService.selectNursingLevelList(nursingLevel);
            return getDataTable(list);
        }

        /**
         * 查询所有启用的护理等级（用于下拉框）
         */
        @PreAuthorize("@ss.hasPermi('nursing:level:list')")
        @GetMapping("/all")
        public AjaxResult listAll() {
            List<NursingLevel> list = nursingLevelService.selectNursingLevelAll();
            return success(list);
        }

        /**
         * 获取护理等级详细信息
         * 注意：这里必须加上正则，避免 `/all` 被当成 id
         */
        @PreAuthorize("@ss.hasPermi('nursing:level:query')")
        @GetMapping("/{id:\\d+}")
        public AjaxResult getInfo(@PathVariable("id") Long id) {
            return success(nursingLevelService.selectNursingLevelById(id));
        }

        /**
         * 新增护理等级
         */
        @PreAuthorize("@ss.hasPermi('nursing:level:add')")
        @Log(title = "护理等级", businessType = BusinessType.INSERT)
        @PostMapping
        public AjaxResult add(@RequestBody NursingLevel nursingLevel) {
            return toAjax(nursingLevelService.insertNursingLevel(nursingLevel));
        }

        /**
         * 修改护理等级
         */
        @PreAuthorize("@ss.hasPermi('nursing:level:edit')")
        @Log(title = "护理等级", businessType = BusinessType.UPDATE)
        @PutMapping
        public AjaxResult edit(@RequestBody NursingLevel nursingLevel) {
            return toAjax(nursingLevelService.updateNursingLevel(nursingLevel));
        }

        /**
         * 删除护理等级
         */
        @PreAuthorize("@ss.hasPermi('nursing:level:remove')")
        @Log(title = "护理等级", businessType = BusinessType.DELETE)
        @DeleteMapping("/{ids}")
        public AjaxResult remove(@PathVariable Long[] ids) {
            return toAjax(nursingLevelService.deleteNursingLevelByIds(ids));
        }
    }

